package com.cy;

import com.cy.pj.sys.service.realm.ShiroRealm;
import org.apache.shiro.realm.Realm;
import org.apache.shiro.spring.web.config.DefaultShiroFilterChainDefinition;
import org.apache.shiro.spring.web.config.ShiroFilterChainDefinition;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableAsync;

import java.util.LinkedHashMap;

//@EnableAsync//启动异步操作，底层会帮我们配置一个线程池
@SpringBootApplication()
public class FangwuzulinApplication {

    public static void main(String[] args) {
        SpringApplication.run(FangwuzulinApplication.class, args);
    }
    @Bean
    public Realm realm(){//org.apache.shiro.realm.Realm

        return new ShiroRealm();

    }
    @Bean
    public ShiroFilterChainDefinition shiroFilterChainDefinition(){
        DefaultShiroFilterChainDefinition chainDefinition = new DefaultShiroFilterChainDefinition();
        LinkedHashMap<String,String> map = new LinkedHashMap<>();
        //设置允许匿名访问的资源路径（不需要登录即可访问）
        map.put("/bower_components/**", "anon");//anon对应shiro中的有一个匿名过滤器
        map.put("/cgi-bin/**", "anon");
        map.put("/css/**", "anon");
        map.put("/img/**", "anon");
        map.put("/js/**", "anon");
        map.put("/doselectUser","anon");

        //设置需要认证以后才可以访问的资源(注意这里的顺序，匿名访问的放在上面)
        //map.put("/**", "authc");//authc对应有一个认证过滤器，表示认证以后才可以访问
        chainDefinition.addPathDefinitions(map);
        return chainDefinition;
    }

}
